<?php

require_once './include/common.inc.php';

getMyParam('categoryid');

if (!is_numeric($categoryid) || $categoryid <= 0) {
    header("Location:photo.php");
    exit;
}

$page_title = 'jans2en furniture - Photo Gallery - Photo Gallery';
$menu_id = 3;


// *** page code start ***

$sql = "SELECT `id`, `name`, `pic` FROM `photo` WHERE `photo_category_id`=$categoryid";
$query = $db->query($sql);
$sql_all_num = $db->num_rows($query);

$ppp = 1;
getMyParam('page');
$page = empty($page) || !ispage($page) ? 1 : $page;
$start_limit = ($page - 1) * $ppp;
if($start_limit > $sql_all_num) {
    $start_limit = 0;
    $page = 1;
}

$back_page = $page>1 ? $page-1 : 1;
$next_page = $page<$sql_all_num ? $page+1 : $sql_all_num;
$back_page_url = 'photo_details.php?categoryid=' . $categoryid . '&page=' . $back_page;
$next_page_url = 'photo_details.php?categoryid=' . $categoryid . '&page=' . $next_page;
// *** page code end ***

$photo_ary = array();
$sql = "SELECT `id`, `name`, `pic`, `photo_category_id`, `description` FROM `photo` WHERE `photo_category_id`=$categoryid ORDER BY `seq` ASC, `id` DESC LIMIT $start_limit, $ppp";
$photo_ary = $db->get_one($sql);

if (empty($photo_ary)) {
    echo "<script>window.close();</script>";
    exit;
}


$photo_category_ary = array();
$sql = "SELECT `id`, `name` FROM `photo_category` ORDER BY `seq` ASC, `id` DESC";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
    $photo_category_ary[$rs['id']] = $rs['name'];
}

$select_str = '';
foreach ($photo_category_ary as $k=>$v) {
    $selected = "";
    if ($k == $categoryid) {
        $selected = "selected";
        $show_name = $v;
    }
    $select_str .= '<option value="' . $k . '" ' . $selected . '>' . $v . '</option>';
}


 
// ¼ûʵҳϢ
//browseTracking(7,$categoryid,$show_name);
//debug($photo_category_ary[$categoryid]);
	browseTracking(13,0,'Photo Gallery > '.$photo_category_ary[$categoryid].' > '.$show_name.' ( Image No : '.$page.' of '.$sql_all_num.' )' );


require_once PrintEot('photo_details');

?>